package org.jeecg.modules.cosmetic.controller;

import java.util.List;
import javax.annotation.Resource;

import org.jeecg.common.api.dto.CategoryDTO;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.cosmetic.entity.TProduct;
import org.jeecg.modules.cosmetic.handler.ProductHandler;
import org.jeecg.modules.cosmetic.handler.WordReportHandler;
import org.jeecg.modules.cosmetic.model.dto.ProductPageDTO;
import org.jeecg.modules.cosmetic.model.vo.ProductPageVO;
import org.jeecg.modules.cosmetic.model.vo.ProductStatusVO;
import org.jeecg.modules.cosmetic.model.vo.ProductVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.cosmetic.model.vo.ReqIdVO;
import org.jeecg.modules.cosmetic.utils.MyValidateUtil;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: t_product
 * @Author: jeecg-boot
 * @Date: 2022-06-30
 * @Version: V1.0
 */
@Api(tags = "安评报告产品")
@RestController
@RequestMapping("/api/product")
@Slf4j
public class TProductController {

    @Resource
    private ProductHandler productHandler;
    @Resource
    private WordReportHandler wordReportHandler;


    @ApiOperation(value = "分页列表查询", notes = "分页列表查询")
    @GetMapping(value = "/page")
    public Result<IPage<ProductPageDTO>> queryPageList(ProductPageVO productPageVO) {
        return productHandler.getProductPage(productPageVO);
    }

    @ApiOperation(value = "更新产品", notes = "更新产品")
    @PostMapping(value = "/modify")
    public Result<?> modify(@RequestBody ProductVO productVO) {
        MyValidateUtil.validThrow(productVO);
        return productHandler.modifyProduct(productVO);
    }

    @ApiOperation(value = "详情查询", notes = "详情查询")
    @GetMapping(value = "/detail")
    public Result<TProduct> detail(@RequestParam(name = "id", required = true) Long id) {
        return productHandler.getProductByPrimary(id);
    }

    @ApiOperation(value = "作废", notes = "作废")
    @PostMapping(value = "/report_update_status")
    public Result<?> reportUpdateStatus(@RequestBody ProductStatusVO vo) {
        MyValidateUtil.validThrow(vo);
        return productHandler.productInvalid(vo);
    }

    @ApiOperation(value = "修订", notes = "修订")
    @PostMapping(value = "/revise")
    public Result<?> revise(@RequestBody ReqIdVO reqIdVO) {
        MyValidateUtil.validThrow(reqIdVO);
        return productHandler.productRevise(reqIdVO.getId());
    }

    @ApiOperation(value = "产品种类", notes = "产品种类")
    @GetMapping(value = "/category_list")
    public Result<List<CategoryDTO>> categoryList() {
        return productHandler.getProductCategoryList();
    }

    @ApiOperation(value = "生成报告", notes = "生成报告")
    @PostMapping(value = "/report_generate")
    public Result<?> reportGenerate(@RequestBody ReqIdVO reqIdVO) {
        MyValidateUtil.validThrow(reqIdVO);
        return wordReportHandler.generateReport(reqIdVO.getId());
    }
}
